package com.itheima.Executors;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) {
        //创建线程池对象

        //优点：具备延迟执行任务的效果

        ScheduledExecutorService pool = Executors.newScheduledThreadPool(10);
        //延迟执行任务不和主线程竞争
        pool.schedule(()-> {
            int sum = 0 ;
            for (int i = 0; i < 10; i++) {
                sum += i;
                System.out.println("累加："+ i);
            }
            System.out.println(sum);
        }, 10, TimeUnit.SECONDS);
    }
}
